package org.linlinjava.litemall.db.util;

import org.linlinjava.litemall.db.domain.LitemallAftersale;

import java.util.ArrayList;
import java.util.List;

public class AftersaleConstant {
    public static final Short STATUS_INIT = 0;
    // 用户申请 审核中
    public static final Short STATUS_REQUEST = 1;
    // 审核拒绝
    public static final Short STATUS_REJECT = 2;
    // 审核通过
    public static final Short STATUS_RECEPT = 3;
    // 待取件，未安排取件人员
    public static final Short STATUS_WAIT_PICK = 4;
    // 取件中，已安排取件人员
    public static final Short STATUS_PICK_UP = 5;
    // 待自行寄回
    public static final Short STATUS_WAIT_SEND = 6;
    // 待商家收货
    public static final Short STATUS_WAIT_RECEIVE = 7;
    // 换货中
    public static final Short STATUS_EXCHANGE = 8;
    // 售后关闭
    public static final Short STATUS_CANCEL = 9;
    // 退款中
    public static final Short STATUS_REFUND = 10;
    // 售后完成
    public static final Short STATUS_FINISH = 11;

    /**
     * 未收货退款
     */
    public static final Short TYPE_GOODS_MISS = 0;
    /**
     * 退货退款
     */
    public static final Short TYPE_GOODS_NEEDLESS = 1;
    /**
     * 换货
     */
    public static final Short TYPE_GOODS_REQUIRED = 2;

    public static AfterSaleHandleOption build(LitemallAftersale aftersale) {
        short status = aftersale.getStatus();
        AfterSaleHandleOption afterSaleHandleOption = new AfterSaleHandleOption();
        switch (status) {
            case 1:
            case 2:
            case 3:
            case 4:
                afterSaleHandleOption.setUpdate(true);
                afterSaleHandleOption.setCancel(true);
                break;
            default:
        }
        return afterSaleHandleOption;
    }

    // 前端状态转换成后台状态
    public static List<Integer> front2back(Integer state) {
        if (null == state) {
            return null;
        }
        List<Integer> result = new ArrayList<>();
        switch (state) {
            // 待商户处理
            case 1:
                result.add(1);
                result.add(4);
                result.add(5);
                result.add(8);
                result.add(10);
                break;
            // 待用户处理
            case 2:
                result.add(2);
                result.add(6);
                break;
            // 待商户发货
            case 3:
                result.add(7);
                break;
            // 完成
            case 4:
                result.add(0);
                result.add(9);
                result.add(11);
                break;
            default:
        }
        return result;
    }

    // 后台状态转换成前端状态
    public static Integer back2front(Integer state) {
        Integer result = null;
        switch (state) {
            case 1:
            case 4:
            case 5:
            case 8:
            case 10:
                result = 1;
                break;
            case 2:
            case 6:
                result = 2;
                break;
            case 7:
                result = 3;
                break;
            case 0:
            case 9:
            case 11:
                result = 4;
                break;
            default:
        }
        return result;
    }
}
